package com.liang.pcc.controller;

import com.liang.pcc.common.result.Result;
import com.liang.pcc.common.result.Results;
import com.liang.pcc.service.ExcelFileService;
import com.liang.pcc.service.TopologyDataService;
import com.liang.pcc.util.TreeNode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 拓扑结构数据控制层
 */
@RestController
@RequestMapping("/topology")
@RequiredArgsConstructor
public class TopologyDataController {

    private final TopologyDataService topologyDataService;
    private final ExcelFileService excelFileService;

    @GetMapping("/topology")
    public Result<List<TreeNode>> getTopologyData(String fileName) {
        Long fileId = excelFileService.getFileId(fileName);
        List<TreeNode> res = topologyDataService.getTopologyData(fileId);
        return Results.success(res);
    }
}
